import history from '@/utils/history'
import { hasToken } from '@/utils/storage'
import { Toast } from 'antd-mobile'
import React from 'react'
import { Redirect, Route } from 'react-router-dom'

type AtahType = {
  path: string
  component: React.FC
}
// <Route path="/profile/feedback" component={ProfileFeedback} />
export default function AuthRoute({ path, component: Com }: AtahType) {
  return (
    <Route
      path={path}
      render={() => {
        if (hasToken()) return <Com />
        else {
          Toast.show({ content: '登录失效', maskClassName: 'and_toast_err' })
          return (
            <Redirect to={{
              pathname: '/login',
              state: { from: history.location.pathname }
            }}
            />
          )
        }
      }}
    />
  )
}


